package com.example.copa_america;


import java.io.BufferedReader;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;

import android.app.ListActivity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

public class Fixtures extends ListActivity {
	/** Called when the activity is first created. */
	Handler handler;
	TextView textError;
	Alerts alerta;

	public void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main2);
		handler=new Handler();
		textError = (TextView)findViewById(R.id.textView1); 
		alerta = new Alerts(this);
		conectar();
	}
	

	public void conectar() {
		Thread t = new Thread() {

			public void run() {
				BufferedReader in = null;
				try {
					HttpClient client = new DefaultHttpClient();
					HttpGet request = new HttpGet(
							"http://192.168.0.101/Ultima/proyecto2/sedes.xml");
					HttpResponse response = client.execute(request);
					in = new BufferedReader(new InputStreamReader(response
							.getEntity().getContent()));

					final String resultado = in.readLine();
					in.close();
					handler.post(new Runnable() { // This thread runs in the UI 
				          public void run() { 
				             textError.setVisibility(View.VISIBLE); // Update the UI 
				             alerta.setMensaje(resultado);
								alerta.show();  
				          }});
					 

				} catch (Exception e) {
					Log.e("Error en la conexion", e.toString());
					handler.post(new Runnable() { // This thread runs in the UI 
				          public void run() { 
				             textError.setVisibility(View.VISIBLE); // Update the UI 
				             alerta.setMensaje("no pasa nada");
								alerta.show();  
				          }});
					
				}
			}
		};
		t.start();
	}

}
